<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="数据源列表" :width="700" :canFullscreen="false">
    <BasicTable @register="registerTable" :rowSelection="rowSelection"> </BasicTable>
  </BasicModal>
</template>
<script lang="ts" setup>
  import { ref, unref } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { BasicTable, TableAction } from '/@/components/Table';
  import { columns1 } from './rule.data';
  import { sourceRequest } from './rule.api';
  import { useListPage } from '/@/hooks/system/useListPage';
  // 声明Emits
  const emit = defineEmits(['success', 'register']);
  const isUpdate = ref(true);
  const source = ref('');
  const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
    console.log(data.record);
    setModalProps({ confirmLoading: false });
    isUpdate.value = !!data?.isUpdate;
    if (unref(isUpdate)) {
      source.value = data.record;
    }
  });

  // 列表页面公共参数、方法
  const { tableContext } = useListPage({
    tableProps: {
      title: '数据源列表',
      api: sourceRequest,
      columns: columns1,
      showIndexColumn: true,
      showActionColumn: false,
      useSearchForm: false,
      beforeFetch(params) {
        params.source = source.value;
      },
    },
  });

  const [registerTable, { reload }] = tableContext;
</script>
<style scoped></style>
